package top.rainbowecho.ai.infrastructure.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.rainbowecho.common.mq.config.BlogMqRouteEnum;
import top.rainbowecho.common.mq.listener.ListenerConfig;

/**
 * 不使用自定义元注解原因在于, 使用此种方式不需要在生产者和消费者两边重复定义binding关系，
 * 但是关于此binding的配置两边必须要重复定义
 *
 * @author rainbow
 * @since 2019/12/6 15:05
 */
@Configuration
public class FileToAiListenerConfig extends ListenerConfig {

    @Bean
    public Queue queue() {
        return new Queue(getRouting(BlogMqRouteEnum.FILE_TO_AI));
    }

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(getExchange(BlogMqRouteEnum.FILE_TO_AI));
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(exchange()).with(getRouting(BlogMqRouteEnum.FILE_TO_AI));
    }
}
